<?php

use yii\helpers\Html;
use backend\components\widget\adminLTE\ActiveForm;;
use mdm\admin\components\RouteRule;
use mdm\admin\AutocompleteAsset;
use yii\helpers\Json;
use mdm\admin\components\Configs;

/* @var $this yii\web\View */
/* @var $model mdm\admin\models\AuthItem */
/* @var $form yii\widgets\ActiveForm */
/* @var $context mdm\admin\components\ItemController */

$context = $this->context;
$labels = $context->labels();
$rules = Configs::authManager()->getRules();
unset($rules[RouteRule::RULE_NAME]);
$source = Json::htmlEncode(array_keys($rules));

$js = <<<JS
    $('#rule_name').autocomplete({
        source: $source,
    });
JS;
AutocompleteAsset::register($this);
$this->registerJs($js);
?>
<?php $form = ActiveForm::begin(['id' => 'item-form']); ?>
    <div class="box-body">
        <?= $form->field($model, 'name')->textInput(['maxlength' => 64]) ?>
        <?= $form->field($model, 'description')->textarea(['rows' => 2]) ?>
        <?= $form->field($model, 'ruleName')->textInput(['id' => 'rule_name']) ?>
        <?= $form->field($model, 'data')->textarea(['rows' => 6]) ?>
    </div>
    <div class="box-footer">
        <div class="pull-right">
            <?= Html::submitButton('<i class="fa fa-save"></i> 保存', ['class' => 'btn btn-success']) ?>
        </div>
    </div>

<?php ActiveForm::end(); ?>
